package my.springboot3.config;

import my.springboot3.utils.HeaderInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 拦截器
     */
    @Autowired
    private HeaderInterceptor headerInterceptor;

    /**
     * 添加拦截器
     *
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // registry,用于注册拦截器的接口
        // 该对象可以添加自定义的拦截器，并指定这些拦截器需要拦截或排除的路径
        // 拦截所有请求，除了登录请求,还有图片
        registry.addInterceptor(headerInterceptor)
                // .addPathPatterns("/**")
                .excludePathPatterns("/user/register",
                                                "/user/login",
                                                "/image/**");
    }


}